/*
 * @(#)EmailMessageSenderComparator.java
 *
 * Copyright (c) 2004 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */

package com.dcivision.upgrade;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Responsibility to process exception caused in upgrading. Implements do they
 * special process by override {@link #handleException(UpgradeContext)}.
 * 
 * @author      Brook.Huang
 * @company     DCIVision Limited
 * @creation    19/04/2007
 * @version     $Revision: 1.3 $
 */
public abstract class UpgradeExceptionHandler {
  protected Log log = LogFactory.getLog(UpgradeExceptionHandler.class);

  protected String exceptionClassName = null;

  public UpgradeExceptionHandler() {
    super();
  }

  public UpgradeExceptionHandler(String exceptionClassName) {
    this.exceptionClassName = exceptionClassName;
  }

  /**
   * Compare given exception with current handler itself, return
   * <code>false</code> just if this handler have special
   * <code>exceptionClassName</code> which is seted in constructor
   * {@link #UpgradeExceptionHandler(String)} and this
   * <code>exceptionClassName</code> doesnt equals with griven exception's
   * class name.
   */
  public boolean matches(Throwable exception) {
    if (exception == null) {
      return (false);
    }

    boolean matches = true;

    if (exceptionClassName != null && !exceptionClassName.equals(exception.getClass().getName())) {
      matches = false;
    }

    return matches;
  }

  public abstract void handleException(UpgradeContext upgradeContext) throws Exception;

}
